﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">

    $(function() {
        intityUserTree_WF();
    })

    function intityUserTree_WF() {
        $.ajax({
            url: "/Home/getUserTree",
            type: "POST",
            success: function(userNodes) {
                setting.callback.onCheck = onUsertreeCheck_WF;
                $.fn.zTree.init($("#treeDemo_wfprocess"), setting, eval(userNodes));
                var visible = $("#treevis").val();
                // alert(visible);
                if (visible == "T") {
                    $("#treeDemo_wfprocess").show();
                }
                else if (visible = "F") {
                    $("#treeDemo_wfprocess").hide();
                }
            }
        });
    }

    $("#steplist").change(function IntityTree() {
        var taskname = $(this).val();
        //var taskname = $("#steplist option:selected").val();
        var taskdes = $("#steplist option:selected").text();
        var task_id = $("#task_id").val();
        $("#task_des").attr("value", taskdes);
        var guid = $("#txtGUID").val();
        $.ajax({
            type: "POST",
            url: "/WorkFlow/InityTree",
            data: { eventDrivenName: taskname, eventDrivenDesc: taskdes, guid: guid, task_id: task_id },
            success: function(restag) {
                if (restag.res != true) {
                    alert(restag.msg);
                }
                if (restag.data != "[]") {
                    $.fn.zTree.init($("#treeDemo_wfprocess"), setting, eval(restag.data));
                    $("#treeDemo_wfprocess").show();
                }
                else {
                    $("#treeDemo_wfprocess").hide();
                    $("#selectarr").attr("value", ""); //清空赋值
                }
            }
        });
    });


    //统计tree上选中的人员，将其组成一个字符串数组存放在 id=selectarr 隐藏标签中
    function onUsertreeCheck_WF(event, treeId, treeNode) {
        //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo_wfprocess");
        var nodes = treeObj.getCheckedNodes(true);

        var temp = "";
        for (i = 0; i < nodes.length; i++) {
            temp = temp + nodes[i].id + ",";
        }
        $("#selectarr").attr("value", temp);
    };

    function OnSubmit() {
        //如果显示，则必须选择一个处理人
        if ($("#treeDemo_wfprocess").is(":visible") && $("#selectarr").val() == "") {
            alert("最少选择一个处理人！");
            return false;
        }
        var selectstep = $("#steplist").val();
        if (selectstep == "") {
            alert("请选择审批操作");
            return false;
        }
        show_cover();
        return true;
    }

    //附件获取
    function doGetAppendix() {
        var uniqueid = $("#txtGUID").val();
        $.ajax({
            url: "/WorkFlow/DoGetAppendix",
            type: "POST",
            data: { "uniqueid": uniqueid },
            success: function(data) {
                if (data == "landfail") {
                    alert("该文件不存在");
                }
            }
        })
    }

    function proRes(ajaxContext) {
        var restag = {};
        try {
            restag = ajaxContext.get_response().get_object();
        } catch (e) {
            alert("程序出现错误，请联系管理员");
            return;  // return if result is not json
        }

        if (restag.res != true) {
            alert(restag.msg);
            return;
        }
        else {
            alert("操作成功");
        }
        //var a = document.getElementById("workarea-1-1");
        var b = document.getElementById("workarea-2-2");
        if (b != null) {
            $('#menu_wfcurtasklist').trigger('click');
        }
        $('#menu_worktable').trigger('click');
        $.fn.deltab('2-2-examine');
        hide_cover();
    }
</script>

<div id="wfprocess" style="padding-top: 35px;">
    <div id="m">
        <%using (Ajax.BeginForm("DoWFProcess", "WorkFlow",
              new AjaxOptions { UpdateTargetId = "temp", OnSuccess = "proRes" }))
          { %>
        <div id="div_bd_main" style="margin-top: 20px;">
            <div style="width: 625px; float: left; margin-left: 10px; background-color: #F9F9F9;
                border: solid 1px #6C92AD;">
                <div id="div_hidenvalue">
                    <%=Html.Hidden("user_id", ViewData["user_id"])%>
                    <%=Html.Hidden("form_id", ViewData["form_id"])%>
                    <%=Html.Hidden("task_id", ViewData["task_id"])%>
                    <%=Html.Hidden("ptask_id", ViewData["ptask_id"])%>
                    <%=Html.Hidden("task_name")%>
                    <%=Html.Hidden("task_des")%>
                    <%=Html.Hidden("selectarr", ViewData["clrs"])%>
                    <%=Html.Hidden("treedefi", ViewData["treedefi"])%>
                    <%=Html.Hidden("treevis", ViewData["treevisible"])%>
                    <%=Html.Hidden("str_id", ViewData["str_id"])%>
                </div>
                <div id="div_bd" style="position: relative; width: 600px; height: 800px; margin-left: 13px;
                    padding: 5px; overflow: auto">
                    <% Response.Write(ViewData["formdefi"]); %>
                </div>
            </div>
            <%--            <div style="float: left; height: 800px; width: 340px;">
                <div style="width: 340px; height: 500px; padding: 0 0 0 10px;">
                    <div id="div_bd_tail" style="width: 300px; height: 150px;">--%>
            <div style="float: left; height: 800px; width: 310px; margin-left: 40px;">
                <div style="width: 300px; height: 500px; float: left; position: fixed; top: 130px;
                    left: 950px;">
                    <div id="div_bd_tail" style="width: 300px; height: 150px; float: left;">
                        <%=Html.Hidden("txtGUID", ViewData["uniqueid"])%>
                        审批操作：<%=Html.DropDownList("steplist", "=选择=")%><br />
                        审批建议：<br />
                        <%=Html.TextArea("task_clyj", "", new { style="width:250px;border:solid 1px #6C92AD;"})%>
                        <%--//附件div--%>
                        <%if (ViewData["wfappendix"] != null)
                          {%>
                        <br />
                        附件：<%=ViewData["wfappendix"]%>
                        <%} %><br />
                        <input class="btn_style" style="margin-top: 8px;" type="submit" value="确定" onclick="return OnSubmit();" />
                    </div>
                    <div id="div_tree" class="zTreeDemoBackground left" style="height: 240px;">
                        <ul id="treeDemo_wfprocess" class="ztree" style="height: 230px; width: 260px; float: left">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <%} %>
    </div>
</div>
